package controller;

import userBiz.UserBiz;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/user.let")
public class UserServlet extends HttpServlet {
    UserBiz userBiz=new UserBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String type=request.getParameter("type");
        PrintWriter out=response.getWriter();
        if ("login".equals(type)){
            String name=request.getParameter("name");
            String pwd=request.getParameter("pwd");
            if (userBiz.loginCheck(name,pwd)) {
                out.print("{\"success\":\"true\"}");
            }else{
                out.print("{\"success\":\"false\"}");
            }
        }
    }
}
